package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;


@Aspect
public class AnnoAdvice {
    //切点
    @Pointcut("execution(* com.dao.impl.UserDapImpl.*(..))")
    public void pointcut() {
    }

    //前置通知
    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        System.out.println("这是前置通知!");
        System.out.println("目标类:" + joinPoint.getTarget());
        System.out.println(",被织入增强的目标方法为:" + joinPoint.getSignature().getName());
    }

    //环绕通知
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("这是环绕通知之前的部分!");
        //通知目标方法
        Object object = point.proceed();
        System.out.println("这是环绕通知之后的部分!");
        return object;
    }

    //异常通知
    @AfterThrowing("pointcut()")
    public void afterException() {
        System.out.println("异常通知!");
    }
    //后置通知
    @After("pointcut()")
    public void after() {
        System.out.println("这是后置通知!");
    }
}
